package master;

/**
 *
 * 整数转罗马数字：模拟，先编码
 *
 * @author chenyw
 * @date 2022/7/23 10:59
 */
public class M12intToRoman {
    private int[] arr = new int[] {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4,1};
    private String[] symbolics = new String[] {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
    public String intToRoman(int num) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < arr.length; i++) {
            while (num >= arr[i]) {
                sb.append(symbolics[i]);
                num -= arr[i];
            }
            if (num == 0) {
                break;
            }
        }
        return sb.toString();

    }
}
